package com.gcsoftware.web.mapper;

import com.gcsoftware.web.beans.T_GW_COMPANY;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by qs on 2018/3/14.
 */
@Mapper
public interface T_GW_COMPANYMAPPER {

    @Select("<script>SELECT c_COMPANY_ID, c_COMPANY_NAME, c_LINK_MAN, c_LINK_TEL, c_LINK_EMAIL, c_COMPANY_REMARK, c_IS_DEFAULT FROM T_GW_COMPANY WHERE c_COMPANY_STATUS= 'COMPANY_STATUS_NORMAL' <when test='c_COMPANY_NAME != null'>AND c_COMPANY_NAME like  CONCAT(CONCAT('%', #{c_COMPANY_NAME, jdbcType=VARCHAR}), '%')</when><when test='null != c_IS_DEFAULT'> AND c_IS_DEFAULT = #{c_IS_DEFAULT}</when> ORDER BY D_MODIFY_TIME DESC </script>")
    public List<T_GW_COMPANY> queryForList(@Param(value = "c_COMPANY_NAME") String c_COMPANY_NAME,
                                           @Param(value = "c_IS_DEFAULT") Integer c_IS_DEFAULT);

    @Select("SELECT max(c_COMPANY_ID) FROM T_GW_COMPANY WHERE C_COMPANY_ID not like 'DFT_COMPANY_%'")
    public String getMaxId();

    @Select("<script>SELECT c_COMPANY_ID, c_COMPANY_NAME, c_LINK_MAN, c_LINK_TEL, c_LINK_EMAIL, c_COMPANY_REMARK, c_IS_DEFAULT FROM T_GW_COMPANY WHERE 1 = 1 <when test='null != c_COMPANY_ID'>AND c_COMPANY_ID = #{c_COMPANY_ID}</when> <when test='null != c_COMPANY_NAME'>AND c_COMPANY_NAME = #{c_COMPANY_NAME}</when></script>")
    public T_GW_COMPANY get(@Param(value = "c_COMPANY_ID") String c_COMPANY_ID, @Param(value = "c_COMPANY_NAME") String c_COMPANY_NAME);

    @Insert("INSERT INTO T_GW_COMPANY (c_COMPANY_ID, c_COMPANY_NAME, c_LINK_MAN, c_LINK_TEL, c_LINK_EMAIL, c_COMPANY_REMARK,C_COMPANY_STATUS) VALUES (#{c_COMPANY_ID},#{c_COMPANY_NAME},#{c_LINK_MAN},#{c_LINK_TEL},#{c_LINK_EMAIL},#{c_COMPANY_REMARK},#{c_COMPANY_STATUS})")
    public int insert(T_GW_COMPANY company);

    @Update("UPDATE T_GW_COMPANY SET D_MODIFY_TIME=CURRENT_TIMESTAMP , c_COMPANY_NAME= #{c_COMPANY_NAME},C_COMPANY_REMARK = #{c_COMPANY_REMARK}, c_LINK_TEL=#{c_LINK_TEL}, c_LINK_EMAIL =#{c_LINK_EMAIL},C_LINK_MAN = #{c_LINK_MAN} WHERE c_COMPANY_ID = #{c_COMPANY_ID}")
    public int update(T_GW_COMPANY company);

    @Update("UPDATE T_GW_COMPANY SET D_MODIFY_TIME=CURRENT_TIMESTAMP , c_COMPANY_STATUS = #{c_COMPANY_STATUS} WHERE c_COMPANY_ID = #{c_COMPANY_ID}")
    public int updateStatus(@Param(value = "c_COMPANY_ID") String c_COMPANY_ID,@Param(value = "c_COMPANY_STATUS") String c_COMPANY_STATUS);

    @Delete("DELETE FROM T_GW_COMPANY WHERE c_COMPANY_ID = #{c_COMPANY_ID}")
    public int delete(@Param(value = "c_COMPANY_ID") String c_COMPANY_ID);

}
